Option Strict On
Option Explicit On

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Text
Public Class ChartSpaceWrapperDesigner
    Inherits ControlDesigner

    Private m_actionLists As DesignerActionListCollection
    Public Overrides ReadOnly Property AllowResize() As Boolean
        Get
            Return False
        End Get
    End Property

    Public Overrides ReadOnly Property ActionLists() As System.ComponentModel.Design.DesignerActionListCollection
        Get
            If m_actionLists Is Nothing Then
                m_actionLists = New DesignerActionListCollection()
                m_actionLists.Add( _
                    New ChartSpaceWrapperActionList(Component) _
                )
            End If
            Return m_actionLists
        End Get
    End Property
    Public Overrides Function GetDesignTimeHtml() As String
        Dim designedControl As ChartSpaceWrapper = _
            DirectCast(Component, ChartSpaceWrapper)

        ' Since this is a custompaint designer, we will use 
        ' GetDesignTimeHtml to control the size of the design 
        ' surface, using a DIV. The DIV will be sized as per 
        ' the default pixel sizes of the ActiveX control, 
        ' depending on the Autofit and DisplayToolbar 
        ' properties.

        Dim dtHTML As New StringBuilder
        Dim displayWidth As Integer
        Dim displayHeight As Integer

        If designedControl.AutoFit Then
            displayWidth = 504
            If designedControl.DisplayToolbar Then
                displayHeight = 185
            Else
                displayHeight = 163
            End If
        Else
            If designedControl.MaxWidth <> 32000 Then
                displayWidth = designedControl.MaxWidth
            Else
                displayWidth = 543
            End If

            If designedControl.MaxHeight <> 32000 Then
                displayHeight = designedControl.MaxHeight
            Else
                displayHeight = 386
            End If
        End If

        dtHTML.AppendFormat( _
            "<div style='width:{0}px;height:{1}px'>", _
            displayWidth, _
            displayHeight _
        )
        dtHTML.Append("</div")

        Return dtHTML.ToString
    End Function
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        Dim messageFormat As New Drawing.StringFormat()

        messageFormat.LineAlignment = Drawing.StringAlignment.Center
        messageFormat.Alignment = Drawing.StringAlignment.Center

        Dim designedControl As ChartSpaceWrapper = _
            DirectCast(Component, ChartSpaceWrapper)


        With e.Graphics
            Dim clipRect As System.Drawing.RectangleF = GetBounds()
            .FillRectangle(Drawing.Brushes.White, clipRect)
            If designedControl.AutoFit Then
                If designedControl.DisplayToolbar Then
                    .DrawImage( _
                        My.Resources.PivotTableAutoFitToolBar, _
                        clipRect _
                    )
                Else
                    .DrawImage( _
                        My.Resources.PivotTableAutoFitNoToolBar, _
                        clipRect _
                    )
                End If
            Else
                If designedControl.DisplayToolbar Then
                    .DrawImage( _
                        My.Resources.PivotTableToolBar, _
                        clipRect _
                    )
                Else
                    .DrawImage( _
                        My.Resources.PivotTableNoToolBar, _
                        clipRect _
                    )
                End If

            End If


            .DrawString( _
                    "This is a mock-up. Actual content shown will differ.", _
                    New Drawing.Font(Drawing.FontFamily.GenericSerif, 10, Drawing.FontStyle.Bold, Drawing.GraphicsUnit.Point), _
                    Drawing.Brushes.Black, _
                    clipRect, _
                    messageFormat _
            )

        End With

    End Sub

    Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
        MyBase.Initialize(component)

        ' Make this control paint itself at design time
        SetViewFlags(ViewFlags.CustomPaint, True)
    End Sub
End Class
